/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tkgarment.system.dao;

import com.tkgarment.system.domain.MaritalStatus;
import com.tkgarment.system.factory.DAOFactory;
import com.tkgarment.system.inf.IDAO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author zraj
 */
public class MaritalDAO extends AbstractDAO implements IDAO<MaritalStatus, Integer> {

    @Override
    public List<MaritalStatus> getAll() throws Exception {
        String sql = "select * from marital_status order by "+ MaritalStatus.field_status_name +" ASC";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
        List<Map<String, Object>> result = this.getCon().queryList(sql);
        List<MaritalStatus>  ms = new ArrayList<>();
        for (Map<String, Object> map : result) {
            MaritalStatus m = new MaritalStatus();
            m.setStatusId(Integer.parseInt(map.get(MaritalStatus.field_marital_status_id).toString()));
            m.setStatusName(map.get(MaritalStatus.field_status_name).toString());
            ms.add(m);
            
        }
        return ms;
    }

    @Override
    public int updateSingle(MaritalStatus t, Integer id) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int deleteSingle(MaritalStatus t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int insertSingle(MaritalStatus t) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public MaritalStatus getById(Integer id) throws Exception {
        String sql = "select * from marital_status where "+ MaritalStatus.field_marital_status_id +" = ?";
        if (this.getCon() == null) {
            this.setCon(DAOFactory.creatConnection());
        }
        
       Map<String, Object> map = this.getCon().querySingle(sql,id);
       
            MaritalStatus m = new MaritalStatus();
            m.setStatusId(Integer.parseInt(map.get(MaritalStatus.field_marital_status_id).toString()));
            m.setStatusName(map.get(MaritalStatus.field_status_name).toString());
            
        return m;
    }
    
}
